package cn.web.tunnelrobot.service.impl;


import cn.web.tunnelrobot.dao.OperLogDao;
import cn.web.tunnelrobot.pojo.OperLog;
import cn.web.tunnelrobot.pojo.User;
import cn.web.tunnelrobot.service.OperLogService;
import cn.web.tunnelrobot.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;


@Service
public class OperLogServiceImpl implements OperLogService {
    @Autowired
    private OperLogDao operLogDao;

    @Override
    public void insertOperlog(OperLog operLog) {
        operLogDao.insertOperlog(operLog);
    }

    @Override
    public List<OperLog> selectOperLogList(OperLog operLog) {
        return operLogDao.selectOperLogList(operLog);
    }

    @Override
    public HashMap<String, Object> getLogList(String operName, String businessType, String operTime,Integer pageNo, Integer pageSize) {
        HashMap<String,Object> map = new HashMap<String,Object>();
        List<User> list = operLogDao.getLogList(operName,businessType, operTime,((pageNo - 1) * pageSize), pageSize);
        if (list != null) {
            map.put("code", 0);
            map.put("msg", "");
            map.put("count",operLogDao.getLogCount(operName,businessType,operTime));
            map.put("data", list);

        } else {
            map.put("code", -1);
            map.put("msg", "查询失败");
        }
        return map;
    }

    @Override
    public int deleteOperLogByIds(String ids) {
        String[] id_array = ids.split(",");
        return operLogDao.deleteOperLogByIds(id_array);
    }

    @Override
    public OperLog selectOperLogById(Long operId) {
        return operLogDao.selectOperLogById(operId);
    }

    @Override
    public void cleanOperLog() {
        operLogDao.cleanOperLog();
    }
}
